﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OgilvyOne.UKNow.BLL;

using ECCIT;
using OgilvyOne.UKNow.Model;
public partial class admin_UKNOW_news_Press_Download : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GvDataBind();
        }
    }
    protected void Sub_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(this.userName.Text) && !string.IsNullOrEmpty(this.pwd.Text))
        {
            if (CheckName(this.userName.Text).Count==0)
            {
                NewsUserModel model = new NewsUserModel();
                model.Name = this.userName.Text;
                model.Password = this.pwd.Text;
                model.LanguageID = this.LangID;
                ResultInfo res = new NewsUserBLL(this.LangID).Save(model);
                if (res.Result)
                {
                    GvDataBind();
                }
            }
            else
            {
                Response.Write("<script>alert('用户名重复')</script>");
                this.userName.Text = "";
                this.pwd.Text = "";
            }
        }
        else
        {
            Response.Write("<script>alert('请输入用户名和密码')</script>");
        }
    }
    protected void Modified_click(object sender, EventArgs e)
    {
        int uid=int.Parse(((LinkButton)sender).CommandArgument);
        ResultInfo res = new NewsUserBLL(this.LangID).SetStatus(uid);
        if (res.Result)
            GvDataBind();
        else
            Response.Write("<script>alert('修改失败')</script>");
    }
    private void GvDataBind()
    {
        
        IList<NewsUserModel> list = new NewsUserBLL(this.LangID).GetNewsUserModel();
        GridView1.DataSource = list;
        GridView1.DataBind();
        ViewState["source"] = list;
        this.userName.Text = "";
        this.pwd.Text = "";
    }

    private IList<NewsUserModel> CheckName(string name)
    {
       return new NewsUserBLL(this.LangID).CheckName(name);
    }
}